var Combinations=function(){
	var grid;
	var fs,win,pageSize=30;
	var stationmasterfrom=new Ext.FormPanel({
							labelWidth: 75, // label settings here cascade unless overridden
							url:'./?ctrl=combinations&action=update',
							frame:true,
							title: '信息',
							bodyStyle:'padding:0px 0px 0',
							layout:'form',
							width:"100%",
							defaults: {width: 230},
							defaultType: 'textfield',
							items: [{
								fieldLabel: '标题',
								name: 'notice[title]',
								allowBlank:false
							}
							],
							buttons: [{
								text: '更新',
								handler :function(e){
									stationmasterfrom.getForm().submit({
										waitMsg:"提交中",
										failure:function (form,action){Ext.MessageBox.alert("信息","提交失败！");},
										success :function (form,action){
											Ext.MessageBox.alert("信息","提交成功");
											grid.store.reload();
											win.hide();
										}
									});
								},
								scope :this
							},{
								text: '取消',
								handler :function(e){win.hide();}
							}]
						}); 
	win=new Ext.Window({
		title: '編輯用戶',
		layout:'fit',
		width:620,
		height:400,
		closeAction:'hide',
		plain: true,
		items: [stationmasterfrom]
	}); 
	var ds=new Ext.data.Store({
			proxy:new Ext.data.HttpProxy({url:'./?ctrl=ptypes&action=getC'}),
			reader:new Ext.data.JsonReader({},['id','title'])
	});
	var buildGrid = function(){
		grid = new Ext.grid.GridPanel({
			store:ds,
			columns:[
			new Ext.grid.RowNumberer({header :'ID',dataIndex:'id'}),
			{header:'產品類型',width:550,sortable:true,dataIndex:'title',editor:new Ext.form.TextField()}
			],
			viewConfig:{
				forceFit:true
			},
			renderTo:'grid',
			height: 615,
			border:false
		});
		grid.on('afteredit',function(e){
			Ext.Ajax.request({
				url:'./?ctrl=combinations&action=updatePname',
				params:{
				'id':e.record.data.id,
				'product[pname]':e.record.data.pname
				},
				method:'POST',
				success:function(){
				}
			});
		});
		grid.on('cellclick',function(g,rowIndex,columnIndex,e){
			var url="./?ctrl=combinations&action=form&gateWay=1&id="+g.selModel.selections.items[0].data.id;
			var f_dom=Ext.get('safe').dom;
			if(f_dom.src!=url){
				f_dom.src=url;
			}
		});
		grid.store.load();
	};
	var buildLayout = function(){
		var toolbar = new Ext.Panel({
			border:false,
			tbar:[{title:'組合管理'}]
		});

		var layout = new Ext.Viewport({
			layout:'border',
			defaults:{border:false},
			items:[{
				region:'north',
				title:'組合管理',
				height:52,
				items:toolbar
			},{
				region:'west',
				width:180,
				height: 200,
				split:true,
				autoScroll:true,
				items:grid
			},{
				region:'center',
				layout:'fit',
				title:'組合区',
				items:new Ext.Panel({
					renderTo:"panl",
					html : Ext.isIE?'<iframe id="safe" scrolling="auto" frameborder="0" style="width:100%;height:100%;"></iframe>':'<iframe id="safe" scrolling="no" frameborder="0" style="width:100%;height:800px;"></iframe>'
				})
			}]
		});
	}
	return{
		init:function(){
			buildGrid();
			buildLayout();
		}
	}
}();
Ext.onReady(Combinations.init,Combinations);